'/
' drawutil.bmx - version 1.03
' Written 2010 by Anton Berlin.
' 
' =========================================================================
' 
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License as published
' by the Free Software Foundation; either version 3 of the License.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU Lesser General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'/

superstrict

import BRL.Reflection
import BRL.GLMax2D
import BRL.FreeTypeFont
import Pub.Glew

type drawutil

	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Set the current drawing color, and remember the old. Use this the first time you change the drawing
	'// 		color in a sequence of changing colors. The rest of the times, before you need to reset, use the regular
	'// 		'setColor()'. When you're done, do a call to 'resetColor()'.
	'// 
	'// Parameters:
	'// 		(int) r: Red channel.
	'// 		(int) g: Green channel.
	'// 		(int) b: Blue channel.
	'// -------------------------------------------------------------------------------------------------------------
	function setColorInit(r:int, g:int, b:int)
	
		getColor(_oldR, _oldG, _oldB);
		setColor(r, g, b);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Reset to the old drawing color.
	'// -------------------------------------------------------------------------------------------------------------
	function resetColor()
	
		setColor(_oldR, _oldG, _oldB);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Set the current drawing alpha, and remember the old. Use this the first time you change the drawing
	'// 		alpha in a sequence of changing alphas. The rest of the times, before you need to reset, use the regular
	'// 		'setAlpha()'. When you're done, do a call to 'resetAlpha()'.
	'// 
	'// Parameters:
	'// 		(float) alpha: The alpha to use.
	'// -------------------------------------------------------------------------------------------------------------
	function setAlphaInit(alpha:float)
	
		_oldAlpha = getAlpha();
		setAlpha(alpha);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Reset to the old drawing alpha.
	'// -------------------------------------------------------------------------------------------------------------
	function resetAlpha()
	
		setAlpha(_oldAlpha);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Set the current drawing origin, and remember the old. Use this the first time you change the drawing
	'// 		origin in a sequence of changing origins. The rest of the times, before you need to reset, use the regular
	'// 		'setOrigin()'. When you're done, do a call to 'resetOrigin()'.
	'// 
	'// Parameters:
	'// 		(float) alpha: The alpha to use.
	'// -------------------------------------------------------------------------------------------------------------
	function setOriginInit(x:float, y:float)
	
		getOrigin(_oldOriginX, _oldOriginY);
		setOrigin(x, y);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Reset to the old drawing origin.
	'// -------------------------------------------------------------------------------------------------------------
	function resetOrigin()
	
		setOrigin(_oldOriginX, _oldOriginY);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Set the current drawing font, and remember the old. Use this the first time you change the drawing font
	'// 		in a sequence of changing fonts. The rest of the times, before you need to reset, use the regular
	'// 		'setImageFont()'. When you're done, do a call to 'resetFont()'.
	'// 
	'// Parameters:
	'// 		(TImageFont) font: Pointer to the font we wish to use.
	'// -------------------------------------------------------------------------------------------------------------
	function setFontInit(font:TImageFont)
	
		_oldFont = getImageFont();
		setImageFont(font);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Reset to the old drawing font.
	'// -------------------------------------------------------------------------------------------------------------
	function resetFont()
	
		setImageFont(_oldFont);
	
	end function
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Set the colors.
	'// -------------------------------------------------------------------------------------------------------------
	function defaultColor()
	
		setColor(DEFAULT_R, DEFAULT_G, DEFAULT_B);
	
	end function
	function common()
	
		setColor(COMMON_R, COMMON_G, COMMON_B);
	
	end function
	
	function brightRed()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_RED_R, BRIGHT_RED_G, BRIGHT_RED_B);
	
	end function
	function brightGreen()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_GREEN_R, BRIGHT_GREEN_G, BRIGHT_GREEN_B);
	
	end function
	function brightBlue()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_BLUE_R, BRIGHT_BLUE_G, BRIGHT_BLUE_B);
	
	end function
	function brightYellow()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_YELLOW_R, BRIGHT_YELLOW_G, BRIGHT_YELLOW_B);
	
	end function
	function brightTurcose()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_TURCOSE_R, BRIGHT_TURCOSE_G, BRIGHT_TURCOSE_B);
	
	end function
	function brightMagenta()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_MAGENTA_R, BRIGHT_MAGENTA_G, BRIGHT_MAGENTA_B);
	
	end function
	function brightOrange()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_ORANGE_R, BRIGHT_ORANGE_G, BRIGHT_ORANGE_B);
	
	end function
	function brightBrown()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_BROWN_R, BRIGHT_BROWN_G, BRIGHT_BROWN_B);
	
	end function
	function brightPink()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_PINK_R, BRIGHT_PINK_G, BRIGHT_PINK_B);
	
	end function
	function brightGray()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_GRAY_R, BRIGHT_GRAY_G, BRIGHT_GRAY_B);
	
	end function
	function brightMana()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_MANA_R, BRIGHT_MANA_G, BRIGHT_MANA_B);
	
	end function
	function brightPurple()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_PURPLE_R, BRIGHT_PURPLE_G, BRIGHT_PURPLE_B);
	
	end function
	function brightWood()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BRIGHT_WOOD_R, BRIGHT_WOOD_G, BRIGHT_WOOD_B);
	
	end function
	
	function red()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(RED_R, RED_G, RED_B);
	
	end function
	function green()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(GREEN_R, GREEN_G, GREEN_B);
	
	end function
	function blue()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BLUE_R, BLUE_G, BLUE_B);
	
	end function
	function yellow()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(YELLOW_R, YELLOW_G, YELLOW_B);
	
	end function
	function turcose()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(TURCOSE_R, TURCOSE_G, TURCOSE_B);
	
	end function
	function magenta()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(MAGENTA_R, MAGENTA_G, MAGENTA_B);
	
	end function
	function orange()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(ORANGE_R, ORANGE_G, ORANGE_B);
	
	end function
	function brown()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BROWN_R, BROWN_G, BROWN_B);
	
	end function
	function pink()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(PINK_R, PINK_G, PINK_B);
	
	end function
	function gray()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(GRAY_R, GRAY_G, GRAY_B);
	
	end function
	function mana()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(MANA_R, MANA_G, MANA_B);
	
	end function
	function health()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(HEALTH_R, HEALTH_G, HEALTH_B);
	
	end function
	function purple()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(PURPLE_R, PURPLE_G, PURPLE_B);
	
	end function
	function wood()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(WOOD_R, WOOD_G, WOOD_B);
	
	end function
	
	function darkRed()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_RED_R, DARK_RED_G, DARK_RED_B);
	
	end function
	function darkGreen()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_GREEN_R, DARK_GREEN_G, DARK_GREEN_B);
	
	end function
	function darkBlue()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_BLUE_R, DARK_BLUE_G, DARK_BLUE_B);
	
	end function
	function darkYellow()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_YELLOW_R, DARK_YELLOW_G, DARK_YELLOW_B);
	
	end function
	function darkTurcose()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_TURCOSE_R, DARK_TURCOSE_G, DARK_TURCOSE_B);
	
	end function
	function darkMagenta()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_MAGENTA_R, DARK_MAGENTA_G, DARK_MAGENTA_B);
	
	end function
	function darkOrange()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_ORANGE_R, DARK_ORANGE_G, DARK_ORANGE_B);
	
	end function
	function darkBrown()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_BROWN_R, DARK_BROWN_G, DARK_BROWN_B);
	
	end function
	function darkPink()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_PINK_R, DARK_PINK_G, DARK_PINK_B);
	
	end function
	function darkGray()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_GRAY_R, DARK_GRAY_G, DARK_GRAY_B);
	
	end function
	function darkMana()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_MANA_R, DARK_MANA_G, DARK_MANA_B);
	
	end function
	function darkPurple()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_PURPLE_R, DARK_PURPLE_G, DARK_PURPLE_B);
	
	end function
	function darkWood()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(DARK_WOOD_R, DARK_WOOD_G, DARK_WOOD_B);
	
	end function
	
	function white()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(WHITE_R, WHITE_G, WHITE_B);
	
	end function
	function black()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(BLACK_R, BLACK_G, BLACK_B);
	
	end function
	function pitchBlack()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(PITCHBLACK_R, PITCHBLACK_G, PITCHBLACK_B);
	
	end function
	function quest()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(QUEST_R, QUEST_G, QUEST_B);
	
	end function
	function poison()
	
		getColor(_oldR, _oldG, _oldB);
		setColor(POISON_R, POISON_G, POISON_B);
	
	end function
	
	function custom(r:int, g:int, b:int)
	
		getColor(_oldR, _oldG, _oldB);
		setColor(r, g, b);
	
	end function
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Prevent this type from being instantiated.
	'// -----------------------------------------------------------------------------------------------------------------
	method new()
	
		local id:string = TTypeId.forObject(self).name();
		runtimeError("Illegal to create an instance of a namespace class '" + id + "'.");
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		Used when drawing.
	'// -------------------------------------------------------------------------------------------------------------
	global _oldFont:TImageFont;
	global _oldOriginX:float;
	global _oldOriginY:float;
	global _oldAlpha:float;
	global _oldR:int;
	global _oldG:int;
	global _oldB:int;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Description:
	'// 		The colors.
	'// -------------------------------------------------------------------------------------------------------------
	const DEFAULT_R:int = 200;
	const DEFAULT_G:int = 200;
	const DEFAULT_B:int = 200;
	
	const COMMON_R:int = 200;
	const COMMON_G:int = 190;
	const COMMON_B:int = 170;
	
	const BRIGHT_RED_R:int = 255;
	const BRIGHT_RED_G:int = 000;
	const BRIGHT_RED_B:int = 000;
	const BRIGHT_GREEN_R:int = 000;
	const BRIGHT_GREEN_G:int = 255;
	const BRIGHT_GREEN_B:int = 000;
	const BRIGHT_BLUE_R:int = 000;
	const BRIGHT_BLUE_G:int = 000;
	const BRIGHT_BLUE_B:int = 255;
	const BRIGHT_YELLOW_R:int = 255;
	const BRIGHT_YELLOW_G:int = 255;
	const BRIGHT_YELLOW_B:int = 000;
	const BRIGHT_TURCOSE_R:int = 000;
	const BRIGHT_TURCOSE_G:int = 255;
	const BRIGHT_TURCOSE_B:int = 255;
	const BRIGHT_MAGENTA_R:int = 255;
	const BRIGHT_MAGENTA_G:int = 000;
	const BRIGHT_MAGENTA_B:int = 255;
	const BRIGHT_ORANGE_R:int = 255;
	const BRIGHT_ORANGE_G:int = 125;
	const BRIGHT_ORANGE_B:int = 000;
	const BRIGHT_BROWN_R:int = 150;
	const BRIGHT_BROWN_G:int = 100;
	const BRIGHT_BROWN_B:int = 050;
	const BRIGHT_PINK_R:int = 255;
	const BRIGHT_PINK_G:int = 150;
	const BRIGHT_PINK_B:int = 200;
	const BRIGHT_GRAY_R:int = 200;
	const BRIGHT_GRAY_G:int = 200;
	const BRIGHT_GRAY_B:int = 200;
	const BRIGHT_MANA_R:int = 50;
	const BRIGHT_MANA_G:int = 75;
	const BRIGHT_MANA_B:int = 255;
	const BRIGHT_PURPLE_R:int = 127;
	const BRIGHT_PURPLE_G:int = 000;
	const BRIGHT_PURPLE_B:int = 255;
	const BRIGHT_WOOD_R:int = 255;
	const BRIGHT_WOOD_G:int = 170;
	const BRIGHT_WOOD_B:int = 085;
	
	const RED_R:int = 175;
	const RED_G:int = 000;
	const RED_B:int = 000;
	const GREEN_R:int = 000;
	const GREEN_G:int = 175;
	const GREEN_B:int = 000;
	const BLUE_R:int = 000;
	const BLUE_G:int = 000;
	const BLUE_B:int = 175;
	const YELLOW_R:int = 175;
	const YELLOW_G:int = 175;
	const YELLOW_B:int = 000;
	const TURCOSE_R:int = 000;
	const TURCOSE_G:int = 175;
	const TURCOSE_B:int = 175;
	const MAGENTA_R:int = 175;
	const MAGENTA_G:int = 000;
	const MAGENTA_B:int = 175;
	const ORANGE_R:int = 175;
	const ORANGE_G:int = 088;
	const ORANGE_B:int = 000;
	const BROWN_R:int = 100;
	const BROWN_G:int = 067;
	const BROWN_B:int = 033;
	const PINK_R:int = 255;
	const PINK_G:int = 100;
	const PINK_B:int = 175;
	const GRAY_R:int = 125;
	const GRAY_G:int = 125;
	const GRAY_B:int = 125;
	const MANA_R:int = 025;
	const MANA_G:int = 050;
	const MANA_B:int = 200;
	const HEALTH_R:int = 000;
	const HEALTH_G:int = 175;
	const HEALTH_B:int = 000;
	const PURPLE_R:int = 088;
	const PURPLE_G:int = 000;
	const PURPLE_B:int = 175;
	const WOOD_R:int = 175;
	const WOOD_G:int = 117;
	const WOOD_B:int = 058;
	
	const DARK_RED_R:int = 100;
	const DARK_RED_G:int = 000;
	const DARK_RED_B:int = 000;
	const DARK_GREEN_R:int = 000;
	const DARK_GREEN_G:int = 100;
	const DARK_GREEN_B:int = 000;
	const DARK_BLUE_R:int = 000;
	const DARK_BLUE_G:int = 000;
	const DARK_BLUE_B:int = 100;
	const DARK_YELLOW_R:int = 100;
	const DARK_YELLOW_G:int = 100;
	const DARK_YELLOW_B:int = 000;
	const DARK_TURCOSE_R:int = 000;
	const DARK_TURCOSE_G:int = 100;
	const DARK_TURCOSE_B:int = 100;
	const DARK_MAGENTA_R:int = 100;
	const DARK_MAGENTA_G:int = 000;
	const DARK_MAGENTA_B:int = 100;
	const DARK_ORANGE_R:int = 100;
	const DARK_ORANGE_G:int = 050;
	const DARK_ORANGE_B:int = 000;
	const DARK_BROWN_R:int = 060;
	const DARK_BROWN_G:int = 040;
	const DARK_BROWN_B:int = 020;
	const DARK_PINK_R:int = 200;
	const DARK_PINK_G:int = 025;
	const DARK_PINK_B:int = 100;
	const DARK_GRAY_R:int = 050;
	const DARK_GRAY_G:int = 050;
	const DARK_GRAY_B:int = 050;
	const DARK_MANA_R:int = 012;
	const DARK_MANA_G:int = 033;
	const DARK_MANA_B:int = 150;
	const DARK_PURPLE_R:int = 050;
	const DARK_PURPLE_G:int = 000;
	const DARK_PURPLE_B:int = 100;
	const DARK_WOOD_R:int = 100;
	const DARK_WOOD_G:int = 067;
	const DARK_WOOD_B:int = 033;
	
	const WHITE_R:int = 255;
	const WHITE_G:int = 255;
	const WHITE_B:int = 255;
	
	const BLACK_R:int = 020;
	const BLACK_G:int = 020;
	const BLACK_B:int = 020;
	
	const PITCHBLACK_R:int = 000;
	const PITCHBLACK_G:int = 000;
	const PITCHBLACK_B:int = 000;
	
	const QUEST_R:int = 170;
	const QUEST_G:int = 215;
	const QUEST_B:int = 180;
	
	const POISON_R:int = 000;
	const POISON_G:int = 255;
	const POISON_B:int = 100;

end type
